<?php
!defined('P_W') && exit('Forbidden');
require_once R_P.'lib/base/basedb.php';
require_once D_P . 'data/bbscache/house_config.php';
$pwEvaluationDB = House::loadDB('evaluation');
$housefieldsService = House::loadService('HouseFieldsService');
$scoreField =  $housefieldsService->getCompsiteFieldsByType('score');//评分
InitGP(array('hid'),'GP',2);
if (empty($action) || $action == 'search') {
	InitGP(array('hname','content','page','ifcheck'),'GP');
	if ($hid) {
		$_houseinfo = House::loadClass('HouseInfo');
		$houseinfo  = $_houseinfo->getAllInfoById($hid);
		$hname = $houseinfo['name'];
		$_readonly = "readonly";
	}
	$_where = array('hid' => array($hid,'eq'),
					'hname'	=>	array($hname,'like'),
					'content' => array($content,'like'),
					'ifcheck' => array($ifcheck,'eq'));
	$pwEvaluationDB->setBasename($basename."&hid=".$hid."&hname=".urlencode($hname)."&content=".urlencode($content)."&ifcheck=".$ifcheck);
	$ifcheck_Y = $ifcheck_N = '';
	if ($ifcheck == '1') {
		$ifcheck_Y = 'selected';
	} elseif ($ifcheck == '0'){
		$ifcheck_N = 'selected';
	}
	$result = $pwEvaluationDB->searchHouseEvaluation($_where,$page,'admin', true);
	$totalCount = $result['totalCount'] ? $result['totalCount'] : 0;
} elseif ($action == 'check' || $action == 'check_Y' || $action == 'check_N') {
	InitGP(array('id','ifcheck'),'GP');
	empty($id) && adminmsg("请选择要审核的点评信息","$basename&hid=$hid&");
	if ($action == 'check_Y') {
		$ifcheck = 'y';
	} elseif ($action == 'check_N'){
		$ifcheck = 'n';
	}
	$pwEvaluationDB->checkHouseEvaluationsById($id,$ifcheck);
	adminmsg('operate_success',"$basename&hid=$hid&");
} elseif ($action == 'detail') {
	define('AJAX',1);
	InitGP(array('id'),'GP',2);
	$result = $pwEvaluationDB->searchHouseEvaluation(array('id'=>array($id,'eq')),$page='all',$f = 'admin');
	include PrintMode('evaluation');ajax_footer();
}elseif ($action == 'del') {
	InitGP(array('id'),'GP',2);
	!$id && adminmsg("请选择要删除的评论","$basename&hid=$hid&");
	$pwEvaluationDB->deleteHouseEvaluationsByID($id,$hid);
	$pageCache = getPageCache('info',$hid);
	$pageCache->deleteCache('evaluations');
	adminmsg('operate_success',"$basename&hid=$hid&");
} elseif ($action == 'score') {
	InitGP(array('step','hid'),'GP',2);
	!$hid && adminmsg("请选择楼盘信息！","admin.php?adminjob=mode&admintype=house_info");
	if (empty($step)) {
		$scoreinfo = $result = array();
		$result = $pwEvaluationDB->getScoreByHid($hid);
		$scoreinfo = $result['scoreinfo'];
		!$scoreinfo['actually'] && $scoreinfo['actually'] = 0;
		!$scoreinfo['userdefined'] && $scoreinfo['userdefined']=0;
		!$scoreinfo['avescore'] && $scoreinfo['avescore'] = 0;
		if (is_array($scoreField)) {
			foreach ($scoreField as $key => $value) {
				if (!$scoreinfo[$key]) {
					$scoreinfo[$key] = array('actually'=>0,'added'=>0);
				}
			}
		}
	} elseif ($step == 2) {
		InitGP(array('userdefined','content'),'GP',2);
		InitGP(array('total'),'GP',1);
		(empty($userdefined) || $userdefined < 0) && $userdefined = 0;
		$scoreinfo = array();
		foreach ($content as $key => $value) {
			$scoreinfo[$key] = array(0,(int)$value);
		}		
		$pwEvaluationDB->insertScoreInfoByHid($hid,$scoreinfo,$total,$userdefined);
		adminmsg('operate_success',"$basename&action=$action&hid=$hid&");
	}
}
include PrintMode('evaluation');
exit;
?>